package logic.threads;

import java.util.ArrayList;

import logic.blocks.Block;
import logic.characters.Player;
import logic.enemies.Enemy;
import logic.projectiles.Grenade;
import logic.pruebas.GamePanel;

/**
 * @author Unai
 * Hilo del especial de Marco
 *
 */
public class ThrowGrenade implements Runnable{
	private float coorX;
	private float coorY;
	private boolean direction;
	private GamePanel panel;
	private ArrayList<Enemy> enemies;
	private ArrayList<Block> blocks;
	private Player player;
	private int damage;
	
	/**
	 * @param coorX
	 * @param coorY
	 * @param panel
	 * @param direction
	 * @param enemies
	 * @param blocks
	 * @param damage
	 * @param friendly
	 * @param player
	 */
	public ThrowGrenade(float coorX, float coorY, GamePanel panel, boolean direction, ArrayList<Enemy> enemies, ArrayList<Block> blocks, int damage, boolean friendly, Player player) {
		this.coorX = coorX;
		this.coorY = coorY;
		this.direction = direction;
		this.panel = panel;
		this.enemies = enemies;
		this.blocks = blocks;
		this.damage = damage;
		this.player = player;
	}

	@Override
	public void run() {
		Grenade grenade = new Grenade(coorX, coorY, panel, "resources/grenade.gif", direction, damage);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		grenade.dibujar();
		while (!grenade.impacted) {
			grenade.update();
			
			for (Enemy e : enemies) {
				grenade.impact(e);
			}
			
			for (Block b : blocks) {
				grenade.impact(b);
			}
		}
		panel.remove(grenade);
		panel.updateUI();
		
	}

}
